package com.xuhai.blog.api;

import com.xuhai.blog.admin.entity.ArticleEntity;
import com.xuhai.blog.admin.service.ArticleService;
import com.xuhai.blog.admin.service.BannerService;
import com.xuhai.blog.admin.service.CategoryService;
import com.xuhai.blog.admin.service.WebsiteService;
import com.xuhai.blog.common.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author PangJunjie
 * @Date 2022/2/15/015
 */
@RestController
@RequestMapping("/api")
public class ApiIndexController {

    @Autowired
    private WebsiteService websiteService;

    @Autowired
    private BannerService bannerService;

    @Autowired
    private ArticleService articleService;

    @Autowired
    private CategoryService categoryService;


    @GetMapping("/website")
    public ResultJson website(){
        return ResultJson.ok().data(websiteService.getById(1));
    }

    @GetMapping("/banner")
    public ResultJson banner(){
        return ResultJson.ok().data(bannerService.getBannerList());
    }

    @GetMapping("/href")
    public ResultJson href(){
        return ResultJson.ok().data(bannerService.getHrefList());
    }

    @GetMapping("/total")
    public ResultJson total(){
        ArticleEntity article = new ArticleEntity();
        article.setStatus(1);
        article.setArticleStatus(1);
        Map<String, Object> map=new HashMap<>();
        map.put("articleCount",articleService.getCount(article));
        map.put("categoryCount",categoryService.getCount(1));
        return ResultJson.ok().data(map);
    }
}
